package com.hsj.goldstore.mvp.view;

import android.os.Bundle;
import android.support.v4.content.Loader;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hsj.goldstore.R;
import com.hsj.goldstore.adapter.GoodsAdapter;
import com.hsj.goldstore.adapter.GridItemDivider;
import com.hsj.goldstore.base.BaseMvpActivity;
import com.hsj.goldstore.base.PresenterFactory;
import com.hsj.goldstore.base.PresenterLoader;
import com.hsj.goldstore.bean.GoodsBean;
import com.hsj.goldstore.bean.LoginBean;
import com.hsj.goldstore.mvp.present.MyCouponPresent;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/3/26.
 */

public class MyGoodsActivity extends BaseMvpActivity<MyCouponPresent, MyCouponView> implements MyCouponView, XRecyclerView.LoadingListener {


    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.btn_right)
    TextView btnRight;
    @BindView(R.id.m_recyclerview)
    XRecyclerView mRecyclerview;

    private GoodsAdapter adapter;

    @Override
    protected int getResouseId() {
        return R.layout.activity_buy_record;
    }

    @Override
    protected void initView() {
        tvTitle.setText("我的商品");
        btnRight.setVisibility(View.GONE);
        initRecyclyview();
    }

    private void initRecyclyview() {
        GridLayoutManager manager = new GridLayoutManager(this, 2);
        mRecyclerview.setLayoutManager(manager);
        mRecyclerview.setPullRefreshEnabled(true);
        mRecyclerview.setLoadingMoreEnabled(true);
        mRecyclerview.setLoadingMoreProgressStyle(ProgressStyle.BallSpinFadeLoader);
        mRecyclerview.setLoadingListener(this);
        mRecyclerview.addItemDecoration(new GridItemDivider());
    }

    @Override
    protected void initData() {
        presenter.getCouponList();
    }

    @Override
    public Loader<MyCouponPresent> onCreateLoader(int id, Bundle args) {
        return new PresenterLoader<>(this, new PresenterFactory<MyCouponPresent>() {
            @Override
            public MyCouponPresent create() {
                return new MyCouponPresent();
            }
        });
    }

    @Override
    public void setData(List<GoodsBean> list) {
        adapter = new GoodsAdapter(this, list);
        mRecyclerview.setAdapter(adapter);
    }

    @Override
    public void refreshComplete() {
        mRecyclerview.refreshComplete();
    }

    @Override
    public void noMore(boolean more) {
//        mRecyclerview.setNoMore(more);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onRefresh() {
        presenter.refresh();
    }

    @Override
    public void onLoadMore() {
        presenter.loadMore();
    }
}
